﻿
@model IOA.MES.DataAccess.VModel.VIVTemp
@{
    ViewBag.Title = "IV温度配置";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div style="background-color:white;padding:10px;margin:15px">
        <div class="layui-form">
            <div class="layui-form-item" pane="">
                <label class="layui-form-label" v-html="lang.Field.TempMin">温度下限</label>
                <div class="layui-input-inline">
                    <input type="number" name="TempMin" min="0" value="@(Model?.TempMin)" autocomplete="off" class="layui-input">
                </div>

            </div>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label" v-html="lang.Field.TempMax">温度上限</label>
                <div class="layui-input-inline">
                    <input type="number" name="TempMax" min="0" value="@(Model?.TempMax)" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn " lay-submit lay-filter="submit">保存</button>
                </div>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);
        function initLayui() {
            layui.use(['form', 'layer'], function () {
                var layer = layui.layer,
                    form = layui.form;

                form.on('submit(submit)', function (data) {
                    var forms = data.field;
                    console.log(data.field);
                    if (forms.TempMin.trim() != "" && forms.TempMax.trim() != "" && !isNaN(forms.TempMin) && !isNaN(forms.TempMax)
                        && parseFloat(forms.TempMax) <= parseFloat(forms.TempMin)) {
                        layer.msg("温度下限必须小于温度上限", { icon: 5 });
                        return;
                    }
                    var loadId = layer.load();
                    $.ajax({
                        async: false,
                        url: "/ParaSetting/SaveIVTemp",
                        data: {
                            model: {
                                TempMin: forms.TempMin.trim() == "" ? null : forms.TempMin.trim(),
                                TempMinContains: true,
                                TempMax: forms.TempMax.trim() == "" ? null : forms.TempMax.trim(),
                                TempMaxContains: false
                            }
                        },
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("保存成功！", { icon: 6, time: 1500 });
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
